<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css">

	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/doc.min.css">
	<style>
	.tree li{
        list-style-type: none;
		cursor:pointer;
	}
	</style>
</head>
<body>
<div class="col-sm-12 col-sm-offset-0 col-md-12 col-md-offset-0 main">
		<ol class="breadcrumb">
		  <li><a href="#">首页</a></li>
		  <li><a href="#">所有权登记申请</a></li>
		</ol>
		<div class="panel panel-default">
	      <div class="panel-heading">表单数据<div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
		  	<div class="panel-body" id="body">
				<%@ include file="ROOTWO.jsp"%>
		 	</div>
		</div>
      </div>
    <script src="${pageContext.request.contextPath}/jquery/jquery-2.1.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/script/docs.min.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/jquery-1.12.3.min.js"></script>
	<script type="text/javascript">
		$(function(){
			getHouse();
		});
		function getHouse(){
			$("#inquire").click(function(){
				var house_id=$("#house_id").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/house/selectHouseById",
					type:"post",
					async:true,
					data:{"house_id":house_id},
					dataType:"json",
	       			error:function(){
	       				alert("没有找到！");
	       			},
	       			success:function(data){
	       				var divStr="<table class='table table-condensed'>";
	       				divStr=divStr+"<tr>";
	       				divStr=divStr+"<th>房屋编号</th>";
	       				divStr=divStr+"<th>房屋面积</th>";
	       				divStr=divStr+"<th>房屋户型</th>";
	       				divStr=divStr+"<th>房屋楼层</th>";
	       				divStr=divStr+"</tr>";
	       				divStr=divStr+"<tr>";
	       				divStr=divStr+"<input id='house_id' type='hidden' value='"+data.h_id+"'/>";
	       				divStr=divStr+"<td>"+data.house_id+"</td>";
	       				divStr=divStr+"<td>"+data.house_area+"</td>";
	       				divStr=divStr+"<td>"+data.house_shape+"</td>";
	       				divStr=divStr+"<td>"+data.house_floor+"</td>";
	       				divStr=divStr+"</tr>";
	       				divStr=divStr+"</table>";
	       				divStr=divStr+"<div style='height:60px;width:300px;padding:20px;float:right;'>";
	       				divStr=divStr+"<button type='button' class='btn btn-primary' id='verify'>所有权</button>";
	       				divStr=divStr+"<a href='${pageContext.request.contextPath}/heright/skipHeright?h_id="+data.h_id+"&house_id="+data.house_id+"'><button type='button' class='btn btn-primary'>他项权</button></a>";
	       				divStr=divStr+"<a href='ROO.jsp'><button type='button' class='btn btn-primary'>返回</button></div></a>";
	       				$("#body").html(divStr);
	       				ownership();
	       			}
	       			
				});
			});
		};
		function ownership(){
			$("#verify").click(function(){
				var house_id=$("#house_id").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/user/selectUserByHouseId",
					type:"post",
					async:true,
					data:{"house_id":house_id},
					dataType:"json",
	       			error:function(){
	       				alert("没有用户！");
	       			},
	       			success:function(data){
	       				var divStr="<table class='table table-condensed'>";
	       				divStr=divStr+"<tr>";
	       				divStr=divStr+"<th>用户编号</th>";
	       				divStr=divStr+"<th>用户姓名</th>";
	       				divStr=divStr+"<th>用户年龄</th>";
	       				divStr=divStr+"<th>用户电话</th>";
	       				divStr=divStr+"<th>占有份额</th>";
	       				divStr=divStr+"<th>房屋年限</th>";
	       				divStr=divStr+"<th>权限类型</th>";
	       				divStr=divStr+"</tr>";
	       				divStr=divStr+"<input id='dataNum' type='hidden' value='"+data.userList.length+"'/>";
	       				for(var i=0;i<data.userList.length;i++){
	       					divStr=divStr+"<tr>";
	       					divStr=divStr+"<input id='u_id"+i+"' type='hidden' value='"+data.userList[i].u_id+"'/>";
		       				divStr=divStr+"<td id='user_id"+i+"'>"+data.userList[i].user_id+"</td>";
		       				divStr=divStr+"<td>"+data.userList[i].user_name+"</td>";
		       				divStr=divStr+"<td>"+data.userList[i].user_age+"</td>";
		       				divStr=divStr+"<td>"+data.userList[i].user_phone+"</td>";
		       				divStr=divStr+"<td><input type='text' placeholder='请输入占有份额' id='user_share"+i+"'value='"+data.userList[i].user_share+"'/></td>";
		       				divStr=divStr+"<td><input type='text' placeholder='请输入房屋年限' id='h_years"+i+"' value='";
		       				if(data.roo!=''){
		       					divStr=divStr+data.roo.h_years;
		       				}
		       				divStr=divStr+"'/></td>";
		       				divStr=divStr+"<td>所有权</td>";
		       				divStr=divStr+"</tr>";
	       				}
	       				divStr=divStr+"</table>";
	       				divStr=divStr+"<div style='height:60px;width:300px;padding:20px;float:right;'>";
	       				divStr=divStr+"<button type='button' class='btn btn-primary' id='submit'>提交</button>";
	       				divStr=divStr+"<a href='ROO.jsp'><button type='button' class='btn btn-primary'>返回</button></div><a>";
	       				$("#body").html(divStr);
	       				updateUser();
	       			}
				});
			});
		};
		function updateUser(){
			$("#submit").click(function(){
				var dataNum=$("#dataNum").val();
				var u_id=[];
				var user_share=[];
				var h_years=[];
				var user_id=[];
				for(var i=0;i<dataNum;i++){
					u_id.push($("#"+"u_id"+i).val());
					user_share.push($("#"+"user_share"+i).val());
					h_years.push($("#"+"h_years"+i).val());
					user_id.push($("#"+"user_id"+i).val());
				};
				$.ajax({
					url:"${pageContext.request.contextPath}/user/updateUser",
					type:"post",
					async:true,
					data:{"u_id":u_id.join(","),"user_share":user_share.join(","),"h_years":h_years.join(",")},
	       			error:function(){
	       				alert("修改失败！");
	       			},
	       			success:function(data){
	       				alert(data);
	       				location.href="${pageContext.request.contextPath}/houseRegister/ROO.jsp";
	       			}
				});
				
			});
		};
	</script>
</body>
</html>